package com.proxy.jdkproxy;


import com.proxy.staticproxy.StaticTargetImpl;
import com.proxy.target.Target;

import java.lang.reflect.Proxy;

/**
 * @Classname JdkProxyTest
 * @Description TODO
 * @Date 2021/8/24 0:25
 * @Created by 张斌
 */
public class JdkProxyTest {
    public static void main(String[] args) {
        testHanler();
        testFactory();
    }

    public static void testHanler(){
        Target target=new StaticTargetImpl();
        target.targetMethod();
        JdkProxyHandler jdkProxyHandler = new JdkProxyHandler(target);
        Target proxyInstance = (Target)Proxy.newProxyInstance(JdkProxyTest.class.getClassLoader(), target.getClass().getInterfaces(), jdkProxyHandler);
        proxyInstance.targetMethod();
    }
    public  static void testFactory(){
        Target target=new StaticTargetImpl();
        target.targetMethod();
        JdkProxyFactory jdkProxyFactory = new JdkProxyFactory(target);
        Target proxyInstance = (Target) jdkProxyFactory.getProxyInstance();
        proxyInstance.targetMethod();
    }
}
